<?php
include '_init_.php';
	$orderManager = Order_Manager::getOrderManager($_REQUEST['id']);
if($orderManager == null)
	exit("Not exist");
if($orderManager->getStatus() != Order_Manager::$STATUS_SAVED)
	exit("Not allowed");
$orderManager->init();

$orderInfo = $orderManager->getInfo();
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$dtSize = new DataTable(constant('DB_TABLE_PHOTO_SIZE'));
if($act == 'save')
{
	$zoom_list = array();
	$zoom_frame_list = array();
	$zoom_frame_list_old = $orderInfo['zoom_frame_list'];
	//construct zoom list data
	$is_gift = isset($_REQUEST['is_gift'])?'Y':'N';
	//foreach($_REQUEST as $reKey=>$reValue)
	//{
		//if(strpos($reKey,'ck_size_id_') === false)
		//	continue;
		$size_id = $_REQUEST['size_id'];
		$size_data = $dtSize->get($size_id);
		$number = intval($_REQUEST['size_number_'.$size_id]);
		foreach($orderInfo['zoom_list'] as $tmpIndex=>$tmpData)
		{
			if($tmpData['size_id'] == $size_id)
			{
				$orderInfo['zoom_list'][$tmpIndex]['number'] = $number;
				$orderInfo['zoom_list'][$tmpIndex]['is_gift'] = $is_gift;
				break;
			}
		}
		//load exist size frame data
		$load_data_number = 0;
		foreach($zoom_frame_list_old as $oldFrameData)
		{
			if($oldFrameData['size_id'] != $size_id)
				continue;
			if($load_data_number == $number)
				break;
			$zoom_frame_list[] = $oldFrameData;			
			$load_data_number++;
		}
		//init empty frame list
		for($i=$load_data_number; $i < $number; $i++)
		{
			$zoom_frame_list[] = array('size_id'=>$size_id,'size_name'=>'','number'=>0,'is_gift'=>$is_gift);
		}
	//}
	$updateOrderData = array('zoom_list'=>$orderInfo['zoom_list'],'zoom_frame_list'=>$zoom_frame_list);

	$orderManager->setInfo($updateOrderData);
	$orderManager->persistOrderInfo();
	AppMain::refreshParentFrame();
}




$sizeList = $dtSize->get_list('','sort_index');

$zoom_list = $orderInfo['zoom_list'];
$zoom_list = Util::convertArrayToMap($zoom_list,'size_id');
$currentZoomData = $zoom_list[$_REQUEST['sizeid']];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form action="cosif.php">
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="id" value="<?php echo $orderManager->getId();?>"/>


<div class="mainf-8">
  <ul>
  <li class="maina-1k">周邊管理-放大相片管理 </li>
      <li class="mainf-1m"><img src="images/line5.gif" width="676" height="7" align="top" /></li>
    <li class="maina-1c2">
<input name="is_gift" type="checkbox" class="article-adminb-chbox" <?php if($currentZoomData['is_gift'] == 'Y'):?> checked="checked" <?php endif;?>/>
贈品
    </li>
    	<?php foreach($sizeList as $tmpData):?>
    	<?php
    		$checked = '';
    		$number = '';
    		if($tmpData['id'] == $_REQUEST['sizeid'])
    		{
    			$checked = 'checked="checked"';
    			$number = $zoom_list[$tmpData['id']]['number'];
    		}else{
    			continue;
    		}
    	?>
    	<li class="maina-1a"><input type="hidden" name="size_id" value="<?php echo $tmpData['id'];?>"/><input type="checkbox" disabled='disabled' <?php echo $checked;?> name="ck_size_id_<?php echo $tmpData['id'];?>" class="article-adminb-chbox"/>&nbsp; <?php echo $tmpData['name'];?> <input name="size_number_<?php echo $tmpData['id'];?>" type="text"  class="maine-keying _validate_form_int" value="<?php echo Util::html_safe($number);?>"/></li>
    	<?php endforeach;?>
     </ul>

</div>

<div class="mainf-7">
<ul>
<li class="article-1g"><input name="" type="button" class="article-1a_btn" value="儲存" onclick="document.forms[0].submit();return false;"/></li>
</ul>
</div>
</form>
</body>
</html>
